#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QFileDialog>
#include <QTimer>
#include <math.h>
#include "box.h"
#include "point.h"
#include "scene.h"
#include "camera.h"
#include "lighting.h"

// FIXME: Necessary in Arch Linux
//#include <GL/glut.h>

enum GameState { STOP, PLAY };

class GLWidget : public QGLWidget
{
  Q_OBJECT

public:
  GLWidget(QWidget *parent = 0);
  ~GLWidget();

protected:
  void initializeGL ();
  void paintGL ();
  void resizeGL (int width, int height);

  virtual void mousePressEvent (QMouseEvent *e);
  virtual void mouseReleaseEvent (QMouseEvent *e);
  virtual void mouseMoveEvent (QMouseEvent *e);
  virtual void keyPressEvent (QKeyEvent *event);

  Scene scene;
  Camera cam;
  GameState state;
  Lighting lighting;
  bool culling_enabled;
  int player_rotation;
  QTimer timer;

  typedef  enum {NONE, ROTATE, ZOOM, PAN} InteractiveAction;
  InteractiveAction DoingInteractive;

  int   xClick, yClick;

public slots:
  bool SwitchGame(); // If true game has started
  void ResetGame();
  void SwitchCamera();
  void ResetCamera();
  void SwitchCulling();
  void SwitchDestruction();
  void SwitchInitialLight();
  void SwitchSceneLight();
  void SwitchPlayerLight();
  void InitialLightOptionsWidget();
  void SceneLightOptionsWidget();
  void PlayerLightOptionsWidget();
  void SceneLightPositionX(int);
  void SceneLightPositionZ(int);
  void SetMapSize(int);
  void CarregaPersonatge();
  void RotateCharacter(int);
  void SetEnemyCount(int);
  void CarregaEnemics();
  void UpdateScene();
  void closeEvent(QCloseEvent *);
};

#endif
